package com.atguigu.gmall.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class DelayedMqConfig {
    public static final String exchange_delay = "exchange.delay";
    public static final String routing_delay = "routing.delay";
    public static final String queue_delay_1 = "queue.delay.1";

    //基于插件的延迟交换机
    @Bean
    public Exchange delayExchange(){
        Map arg = new HashMap();
        arg.put("x-delayed-type", "direct");
        return new  CustomExchange(exchange_delay,"x-delayed-message",true,false,arg);
    }

    @Bean
    public Queue delayQueue(){
        return QueueBuilder.durable(queue_delay_1).build();
    }

    @Bean
    public Binding delayBinding(){
        return BindingBuilder.bind(delayQueue()).to(delayExchange()).with(routing_delay).noargs();
    }
}
